import Instructions

'''
意图识别接口
ssh -p 2060 -L 5003:127.0.0.1:5003 cike@202.38.247.166
'''
# if __name__ == "__main__":
#     instructions_identifier = Instructions.Instructions()
#     print(instructions_identifier.judgeSentence("打开财务报表"))
#
# encoding=utf8

# encoding=utf8
import requests
from flask import Flask, request, jsonify

app = Flask(__name__)

'''
    操作识别接口
    接口输入：
        {
        "status": 200, 
        "data": 
            {
                "instruction": "打开财务报表"
            }
        }
'''


@app.route('/OptRecognition', methods=["POST"])
def OptRecognition():
    front_data = request.get_json()
    question = front_data['data']['instruction']
    res = {'is_opt': "", 'exact_opt': ""}
    instructions_identifier = Instructions.Instructions()
    res['is_opt'] = 'y' if instructions_identifier.judgeSentence(question) else 'n'
    if res['is_opt'] == 'y':
        res['exact_opt'] = instructions_identifier.processSentence(question)

    return jsonify(res)


if __name__ == '__main__':
    # 这里host是你的后端地址，这里写0.0.0.0， 表示的是这个接口在任何服务器上都可以被访问的到，只需要前端访问该服务器地址就可以的，
    # 当然你也可以写死，如222.222.222.222， 那么前端只能访问222.222.222.222, port是该接口的端口号,
    # debug = True ,表示的是，调试模式，每次修改代码后不用重新启动服务
    app.run(host='0.0.0.0', port=5001, debug=True)
